Accord Software, Inc.

tutorial02/ptrs.c




/*
 * Accord Software, Inc.
 *
 * Tutorial 02 - CIDL file.
 *
 * Values of the auto variables disappear when the
 * function returns.  Therefore reference values 
 * which are to be returned to the client must be 
 * of type static or malloc'ed.
 *
 * Pointer chasing is automatic.  This example is 
 * for illustrative purpose only.  Generally, lots 
 * of pointer to pointer to the nth degree is not 
 * a good idea.
 *
 * Result is returned as a reference.  
 */

int *
addbyptrs(v, w, x, y, z)
	int v;
	int *w;
	int **x;
	int ***y;
	int ****z;
{
	static int *sum;

	if (!sum)
		sum = (int *)malloc(sizeof(int));

	printf("v = %d\n", v);
	printf("*w = %d\n", *w);
	printf("**x = %d\n", **x);
	printf("***y = %d\n", ***y);
	printf("****z = %d\n", ****z);

	memset(sum, 0, sizeof(int));
	*sum  = (v + *w + **x + ***y + ****z);

	return sum;
}

[ Home | Tutorials | main.c | ptrs.h ]
E-Mail:webmaster@accord.com
[P-043] Updated March 14, 1996
Copyright © 1993-1996 Accord Software, Inc. All rights reserved.